package com.library.service;

import com.library.bean.ReaderCard;
import com.library.dao.AdminBorrowDao;
import com.library.dao.AdminDao;
import com.library.dao.ReaderCardDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginService {

    @Autowired
    private AdminDao adminDao;
    @Autowired
    private ReaderCardDao readerCardDao;

    /*判断管理员账号密码是否存在*/
    public boolean hasMatchAdmin(long adminId, String password) {
        return adminDao.getMatchCount(adminId, password) == 1;
    }

    /*修改管理员密码*/
    public boolean adminRePassword(long adminId, String newPassword) {
        return adminDao.resetPassword(adminId, newPassword) > 0;
    }

    /*获取管理员 名称*/
    public String getAdminUsername(long adminId) {
        return adminDao.getUsername(adminId);
    }

    /*获取管理员 密码*/
    public String getAdminPassword(long adminId) {
        return adminDao.getPassword(adminId);
    }

    /*判断读者账号密码是否存在*/
    public boolean hasMatchReader(long readerId, String password) {
        return readerCardDao.getIdMatchCount(readerId, password) > 0;
    }

    /*修改读者 密码*/
    public boolean readerRePassword(long readerId, String newPassword) {
        return readerCardDao.resetPassword(readerId, newPassword) > 0;
    }

    /*获取读者密码*/
    public String getReaderPassword(long readerId) {
        return readerCardDao.getPassword(readerId);
    }

    /*查看读者信息*/
    public ReaderCard findReaderCardByReaderId(long readerId) {
        return readerCardDao.findReaderByReaderId(readerId);
    }

}
